import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

//45228
public class P32 {
	public static String subtract(String list, String number) {
		for (int i = 0; i < number.length(); i++) {
			list = list.replaceAll(number.substring(i, i + 1), "");
		}
		return list;
	}
	
	public static void search(int size, String result, List<Integer> resultList, String digitList) {
		//System.out.println(result);
		if (size == result.length()) {
			//System.out.println(">>>" + result);
			resultList.add(Integer.parseInt(result));
			return;
		}
		
		for (int i = 0; i < digitList.length(); i++) {
			int n = Integer.parseInt(digitList.substring(i, i + 1));			
			if (!result.contains(String.valueOf(n))) {
				search(size, result + n, resultList, digitList);
			}
		}
	}
	
	public static void main(String[] args) {
		Set<Integer> sumSet = new HashSet<Integer>();
		String digitLists = "123456789";
		
		for (int i = 1; i <= 4; i++) {
			List<Integer> resultListA = new ArrayList<Integer>();
			String digitListA = digitLists;
			search(i, "", resultListA, digitListA);
			
			for (Integer a : resultListA) {
				String digitListB = subtract(digitLists, String.valueOf(a));
				
				for (int j = 1; j <= 4; j++) {
					if (digitLists.length() < (i + j - 1)) {
						break;
					}
					List<Integer> resultListB = new ArrayList<Integer>();			
					search(j, "", resultListB, digitListB);
					
					for (Integer b : resultListB) {
						String digitListC = subtract(digitListB, String.valueOf(b));
						List<Integer> resultListC = new ArrayList<Integer>();
						search(digitLists.length() - i - j, "", resultListC, digitListC);
						
						for (Integer c : resultListC) {
							if (a * b == c) {
								System.out.println(a + " * " + b + " = " + c);
								sumSet.add(c);
							}
						}	
					}
				}
			}	
		}
		
		Integer[] sumArray = sumSet.toArray(new Integer[0]);
		int sum = 0;
		for (int i = 0; i < sumArray.length; i++) {
			sum += sumArray[i];
		}
		
		System.out.println(sum);
		
	}
}
 